package com.kadron.dao;

import java.util.List;

import javax.persistence.EntityManager;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

import com.kadron.entity.Color;

@AutoCreate
@BypassInterceptors
@Name("colorDAO")
public class KColorDAO extends KDAO<Color> {

	@SuppressWarnings("unchecked")
	public List<Color> getColors(long itemtypeId) {
		EntityManager em = getEntityManager();
		return em.createQuery("SELECT DISTINCT p.color FROM ItemTypeColor p WHERE p.itemType.id = :it_id ORDER BY p.ordinal")
				.setParameter("it_id", itemtypeId)
				.getResultList();
	}
	
	@SuppressWarnings("unchecked")
	public List<Color> getAvailableColors(long ittemtypeId) {
		EntityManager em = getEntityManager();
		return em.createQuery("SELECT DISTINCT e FROM Color e WHERE NOT EXISTS(SELECT 1 FROM ItemTypeColor v WHERE v.color.id=e.id AND v.itemType.id=:it_id) ")
			.setParameter("it_id", ittemtypeId)
			.getResultList();
	}
	
}
